/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Coupled.java
 *
 * Created on 23 бер 2010, 9:50:22
 */

package jmeshless;

import FEMShapeFunction1D.FEMShapeFunction1D1;
import FEMSolver1D.MainMatrixGenerator1;
import Integration.GaussQuadrature;
import Integration.IFunction1D;
import MF1DSolver.MF1DSolver;
import MF1DSolver.MF1SolverLagrangeCoupled;
import MathLib.HashMatrix.HashMatrix;
import MeshlessShapeFunctions.IKernelFunction;
import MeshlessShapeFunctions.JCubicSpline;
import MeshlessShapeFunctions.JExponential;
import MeshlessShapeFunctions.JGaussian;
import MeshlessShapeFunctions.JMeshlessInterpolationFunction1D;
import MeshlessShapeFunctions.JStKernel;
import MeshlessShapeFunctions.Particle;
import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JFrame;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import syntaxanalyser.PostfiksX;

/**
 *
 * @author mark_o
 */
public class Coupled extends javax.swing.JPanel {

    /** Creates new form Coupled */
    public Coupled() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldP = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldQ = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldW = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldF = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jComboBoxA = new javax.swing.JComboBox();
        jTextFieldBLeft = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jComboBoxB = new javax.swing.JComboBox();
        jTextFieldBRight = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldA = new javax.swing.JTextField();
        jTextFieldB = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldN1 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jComboBoxKernal = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldPow1 = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jTextFieldRho1 = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        jTextFieldN2 = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jTextFieldDivPoint = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jTextFieldNorma = new javax.swing.JTextField();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Параметри"));

        jLabel1.setText("p");

        jTextFieldP.setText("1");

        jLabel2.setText("q");

        jTextFieldQ.setText("0");
        jTextFieldQ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldQActionPerformed(evt);
            }
        });

        jLabel3.setText("w");

        jTextFieldW.setText("100");
        jTextFieldW.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldWActionPerformed(evt);
            }
        });

        jLabel4.setText("f");

        jTextFieldF.setText("100");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldP, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldW, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
                            .addComponent(jTextFieldQ, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
                            .addComponent(jTextFieldF, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldQ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldW, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Граничні умови"));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Ліва"));

        jComboBoxA.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Діріхле", "Неймана" }));
        jComboBoxA.setEnabled(false);

        jTextFieldBLeft.setText("0");
        jTextFieldBLeft.setEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jComboBoxA, 0, 116, Short.MAX_VALUE)
            .addComponent(jTextFieldBLeft, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jComboBoxA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldBLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Права"));

        jComboBoxB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Діріхле", "Неймана" }));
        jComboBoxB.setEnabled(false);

        jTextFieldBRight.setText("0");
        jTextFieldBRight.setEnabled(false);
        jTextFieldBRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldBRightActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jComboBoxB, 0, 140, Short.MAX_VALUE)
            .addComponent(jTextFieldBRight, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jComboBoxB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldBRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Проміжок"));

        jLabel5.setText("a");

        jTextFieldA.setText("0");
        jTextFieldA.setEnabled(false);

        jTextFieldB.setText("1");
        jTextFieldB.setEnabled(false);

        jLabel6.setText("b");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldA, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 63, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldB, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Апроксимація безсітковим"));

        jLabel11.setText("n");

        jTextFieldN1.setText("15");

        jLabel12.setText("Ядро");

        jComboBoxKernal.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Гаусіан", "Кубічний сплайн", "Експонентційна", "Експонентційна_2" }));

        jLabel13.setText("Степінь");

        jTextFieldPow1.setText("1");

        jLabel14.setText("Радіус");

        jTextFieldRho1.setText("2.33");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldN1)
                    .addComponent(jComboBoxKernal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldPow1, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFieldRho1, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldN1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(jTextFieldPow1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jComboBoxKernal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(jTextFieldRho1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Апроксимація МСЕ"));

        jTextFieldN2.setText("5");

        jLabel15.setText("n");

        jLabel16.setText("поділ");

        jTextFieldDivPoint.setText("0.95");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(jLabel15)
                .addGap(38, 38, 38)
                .addComponent(jTextFieldN2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel16)
                .addGap(18, 18, 18)
                .addComponent(jTextFieldDivPoint, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16)
                    .addComponent(jTextFieldDivPoint, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldN2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jButton1.setText("Розвязати");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextFieldNorma.setText(" ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextFieldNorma, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldNorma, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldQActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldQActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTextFieldQActionPerformed

    private void jTextFieldWActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldWActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTextFieldWActionPerformed

    private void jTextFieldBRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldBRightActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldBRightActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int nn = Integer.parseInt(this.jTextFieldN1.getText());
        final int N = Integer.parseInt(this.jTextFieldN2.getText());
        int Degree = Integer.parseInt(this.jTextFieldPow1.getText());
        double a = Double.parseDouble(this.jTextFieldA.getText());
        double b = Double.parseDouble(this.jTextFieldB.getText());
        double left = Double.parseDouble(this.jTextFieldBLeft.getText());
        final double divPoint = Double.parseDouble(this.jTextFieldDivPoint.getText());
        boolean DirihletA = true;
        if(this.jComboBoxA.getSelectedIndex()==1){
            DirihletA = false;
        }
        boolean DirihletB = true;
        if(this.jComboBoxB.getSelectedIndex()==1){
            DirihletB = false;
        }
        double right = Double.parseDouble(this.jTextFieldBRight.getText());
        String p = this.jTextFieldP.getText();
        String q = this.jTextFieldQ.getText();
        String w = this.jTextFieldW.getText();
        final String f = this.jTextFieldF.getText();
            IKernelFunction kernal = null;
            double rho = Double.parseDouble(this.jTextFieldRho1.getText());

            ArrayList<Particle> ls1D = new ArrayList<Particle>();
        final ArrayList<JMeshlessInterpolationFunction1D> MeshlessShapeList = new ArrayList<JMeshlessInterpolationFunction1D>();

        double h = (b-divPoint)/(double)nn;
        
        switch(jComboBoxKernal.getSelectedIndex()){
        case 0: kernal = new JGaussian(rho*h); break;
        case 1: kernal = new JCubicSpline(rho*h); break;
        case 2: kernal = new JExponential(0.7,rho*h); break;
        case 3: kernal = new JStKernel(rho*h); break;
        //case 4: kernal = new JSt2Kernel(); break;
        default: kernal = new JGaussian(rho*h);
    }
        
        for (int i = 0; i <=nn; i++) {
            ls1D.add(new Particle(divPoint+h*i, 0, i));
            MeshlessShapeList.add(new JMeshlessInterpolationFunction1D(1, divPoint+i*h, rho*h, kernal));
        }



        ArrayList<Double> list1 = new ArrayList<Double>();

        for (int i = 0; i <= nn; i++) {
            list1.add(a+h*i);
        }

        MF1DSolver solver = new MF1DSolver();
            solver.setfString(f);
            solver.setwString(w);
            solver.setqString(q);
            solver.setpString(p);
        solver.setListOfShapeFunction(MeshlessShapeList);
        solver.setNodeList(ls1D);
        solver.setDirihetB(true);
        solver.setBVal(0.0);
        solver.setDirihetA(false);
        solver.setAVal(0.0);
        solver.setLeft(divPoint);
        solver.setRight(b);


        ///for FEM !!!!!
        //a = 0;
        //b = divPoint;

        h = (divPoint-a)/N;



        solver.FEM_H = h;
//
//
        solver.generate();
//
//
        solver.generatePenalty();
        HashMatrix aAa = solver.getA();
//         aAa = solver.generateLagrangeMulti();




//        FEM
        ArrayList<Double> list = new ArrayList<Double>();
        final ArrayList<FEMShapeFunction1D1> listFEM = new ArrayList<FEMShapeFunction1D1>();

        for (int i = 0; i <= N; i++) {
            list.add(a+h*i);
            listFEM.add(new FEMShapeFunction1D1(a+h*i, h));
        }
        MainMatrixGenerator1 gen = new MainMatrixGenerator1(list);
            gen.setLeft(a);
            gen.setRight(divPoint);
            gen.setfString(f);
            gen.setwString(w);
            gen.setqString(q);
            gen.setpString(p);
            gen.setDirihetB(false);
            gen.setBVal(0.0);
            gen.setDirihetA(true);
            gen.setAVal(0.0);

            gen.Generate();
            gen.applyBounderiesForCoupling();
            MF1SolverLagrangeCoupled cSolverLagrangeCoupled = new MF1SolverLagrangeCoupled(/*solver.getA()*/aAa, gen.getA(),solver.generateBmf(true), gen.generateBFEM(false), solver.getB(),gen.getB(), MeshlessShapeList);
        cSolverLagrangeCoupled.point=divPoint;
        cSolverLagrangeCoupled.generate();
//            cSolverLagrangeCoupled.generate2();

        final double[] res = cSolverLagrangeCoupled.solve();

//        System.out.print("===================================================");
//        for (int i = 0; i < res.length; i++) {
//            System.out.print(res[i]+"\n");
//        }
//        System.out.print("===================================================");

        XYSeries series1 = new XYSeries("розвязок", true, true);

        int NuM = list.size();
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+"\t"+res[i]+"\n");
            series1.add((double)list.get(i),(double)res[i]);
        }
//        for (int i = 0; i < list1.size(); i++) {
//            System.out.print(list1.get(i)+"\t"+res[i+NuM]+"\n");
//            series1.add((double)list1.get(i),(double)res[i+NuM]);
//        }

//    res[res.length-3]*=200000;
        double x = divPoint;
        while(x<=1.000000000000000001){
            double tmp = 0.0;
            for (int j = 0; j <MeshlessShapeList.size(); j++) {
                tmp+= MeshlessShapeList.get(j).calculate(x)*res[j+N];
            }
            System.out.print(x+"\t"+tmp+"\n");
            series1.add(x,tmp);
            x+=0.01;
        }


            NewOkCancelDialog dialog = new NewOkCancelDialog(null, false, new XYSeriesCollection(series1));
            dialog.setLocationRelativeTo(null);
            //dialog.setUndecorated(true);
            dialog.setVisible(true);

            GaussQuadrature gau = new GaussQuadrature(100);

            double r = (gau.Gauss(a, b, 0.000001, new IFunction1D() {

                public double calculate(double x) {
                    if (x<divPoint) {
                        double tmp = 0.0;
                        for (int j = 0; j <listFEM.size(); j++) {
                            tmp+= listFEM.get(j).calculate(x)*res[j];
                        }
                        return tmp*tmp;
                    }else{
                        double tmp = 0.0;
                        for (int j = 0; j <MeshlessShapeList.size(); j++) {
                            tmp+= MeshlessShapeList.get(j).calculate(x)*res[j+N];
                        }
                        return tmp*tmp;
                    }
                    
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));
            this.jTextFieldNorma.setText(r+"");
            System.out.println(r);
            
            r = (gau.Gauss(a, b, 0.01, new IFunction1D() {

                public double calculate(double x) {
                    if (x<divPoint) {
                        double tmp = 0.0;
                        for (int j = 0; j <listFEM.size(); j++) {
                            tmp+= listFEM.get(j).calculate(x)*res[j];
                        }
                        return tmp*tmp;
                    }else{
                        double tmp = 0.0;
                        for (int j = 0; j <MeshlessShapeList.size(); j++) {
                            tmp+= MeshlessShapeList.get(j).calculate(x)*res[j+N];
                        }
                        try {
							return tmp*PostfiksX.Calculate(f, x);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						return 0.0;
                    }
                    
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));
            System.out.println(r);
            

    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBoxA;
    private javax.swing.JComboBox jComboBoxB;
    private javax.swing.JComboBox jComboBoxKernal;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JTextField jTextFieldA;
    private javax.swing.JTextField jTextFieldB;
    private javax.swing.JTextField jTextFieldBLeft;
    private javax.swing.JTextField jTextFieldBRight;
    private javax.swing.JTextField jTextFieldDivPoint;
    private javax.swing.JTextField jTextFieldF;
    private javax.swing.JTextField jTextFieldN1;
    private javax.swing.JTextField jTextFieldN2;
    private javax.swing.JTextField jTextFieldNorma;
    private javax.swing.JTextField jTextFieldP;
    private javax.swing.JTextField jTextFieldPow1;
    private javax.swing.JTextField jTextFieldQ;
    private javax.swing.JTextField jTextFieldRho1;
    private javax.swing.JTextField jTextFieldW;
    // End of variables declaration//GEN-END:variables
    public static void main(String[] args){
        Coupled p = new Coupled();
        JFrame f = new JFrame("одновимірна задача");
        f.add(p);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setMinimumSize(new Dimension(322, 528));
        f.setResizable(false);
        f.setSize(322, 528);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}
